package com.panda.mess.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.panda.mess.dao.MessageMapper;
import com.panda.mess.dao.MessageReplyMapper;
import com.panda.mess.entity.Message;
import com.panda.mess.entity.MessageReply;
import com.panda.mess.entity.MessageVo;
import com.panda.mess.service.MessageService;
import com.panda.sys.entity.User;
import com.panda.utils.Pager;

@Service
public class MessageServiceImp implements MessageService {
	@Resource
	private MessageMapper messageMapper;
	@Resource
	private MessageReplyMapper messageReplyMapper;

	@Override
	public List<User> findAllFriend(Long uid) {
		return messageMapper.findAllFriend(uid);
	}

	@Override
	public Pager<MessageVo> findListLimit(Long offSet, Long pageSize, Long uid, String name) {
		List<MessageVo> topics = messageMapper.findListLimit(offSet, pageSize, uid, name);
		Long count = messageMapper.findListCount(uid, name);
		Pager<MessageVo> pager = new Pager<MessageVo>();
		pager.setItems(topics);
		pager.setRowsCount(count);
		return pager;
	}

	@Override
	public void update(Message message) {
		Message message2 = messageMapper.selectByPrimaryKey(message.getId());
		message2.setIsRead(message.getIsRead());
		messageMapper.updateByPrimaryKey(message2);
	}

	@Override
	public List<MessageVo> findAllMess(Long mid) {
		return messageMapper.findAllMess(mid);
	}

	@Override
	public void saverep(MessageReply messageReply) {
		messageReplyMapper.insert(messageReply);
	}

	@Override
	public void save(Message message) {
		messageMapper.insert(message);
	}
}
